package com.example.actearly_revised;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity {

	protected boolean _active = true;
	protected int _splashTime = 120000; // time to display the splash screen in ms
	SQLogic connector;
	View actionbarView;
	Button startButton;
	@Override
	public void onCreate(Bundle savedInstanceState) {


		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);
		LinearLayout pageLayout=(LinearLayout)findViewById(R.id.splashLayout);
		//pageLayout.setBackgroundResource(R.drawable.background);
		connector = new SQLogic(MainActivity.this);

		getActionBar().setTitle("Act Early");

		//change font failed attempt
		/*

		//this.getActionBar().setDisplayShowCustomEnabled(true);
		//this.getActionBar().setDisplayShowTitleEnabled(false);
		getActionBar();

		LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		actionbarView = inflator.inflate(R.layout.custom_action_bar, null);
		TextView tv= (TextView) actionbarView.findViewById(R.id.actiontitle);
		tv.setTypeface(customFont);
		tv.setTextColor(-1);
		tv.setText("Act Early");
		//tv.setText(this.getTitle());

		getActionBar().setCustomView(tv);
		this.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);*/


		//font change
		//define textviews and buttons so you can change their font
		TextView optText = (TextView) findViewById(R.id.textView1);
		TextView optText1 = (TextView) findViewById(R.id.textView2);
		TextView buttonText= (Button) findViewById(R.id.startButton);
		//TextView CDCText = (TextView) findViewById(R.id.CDCmessage);
		
		//set font of defined textviews/buttons
		Typeface customFont = Typeface.createFromAsset(getAssets(), "fonts/futuram.ttf");
		optText1.setTypeface(customFont);
		optText.setTypeface(customFont);
		buttonText.setTypeface(customFont);
		//CDCText.setTypeface(customFont);


		startButton = (Button) findViewById(R.id.startButton);

		//should do this outside of the thread
		startButton.setOnClickListener(new View.OnClickListener() { 

			public void onClick(View v) {
				//	_active = false;
				finish();
				startActivity(new Intent("com.example.actearly_revised.ModeSelect")); 

			}
		});
		
		// check the database 
		try{

			connector.open();
			Log.d("open", "database");
		}
		catch(Exception e){
			e.printStackTrace();
		}
		if(!(connector.ifDBExist())){
			Log.d("checking", "database");
			connector.close();
			
		}
		else{
			connector.close();
		}
		
		try{
			connector.open();
			connector.RemoveAllHints();
		}
		catch (Exception e){
			e.printStackTrace();
		}
		finally{
			connector.close();
		}
		
		Helpful_Hints_Methods hhm = new Helpful_Hints_Methods(MainActivity.this);

	}


	/*	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			_active = false;
		}
		return true;
	} */

	/*	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	} */


	// thread splash screen code in case we need it
	/*	Thread splashTread = new Thread() {
	@SuppressLint("NewApi")
	@Override
	public void run() {

		try {
			int waited = 0;
			while(_active && (waited < _splashTime)) {
				sleep(100);
				if(_active) {
					waited += 100;
				}

			}
		} catch(InterruptedException e) {
			// do nothing
		} 

		try{

			connector.open();
			Log.d("open", "database");
		}
		catch(Exception e){
			e.printStackTrace();
		}
		if(!(connector.ifDBExist())){
			Log.d("checking", "database");
			connector.close();
			finish();

		}
		else{
			connector.close();
			finish();
		}
	}
};
splashTread.start(); */

}
